package com.example.zhu.controller.user;

import com.example.zhu.Mapper.UserMapper;
import com.example.zhu.dto.Employee;
import com.example.zhu.dto.Reply;
import com.example.zhu.dto.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user")
@Slf4j
public class userController {
    @Autowired
    UserMapper userMapper;
    @GetMapping("/get/{id}")
    public Reply<User> get(@PathVariable(name = "id") String id){
        User user = userMapper.selectByid(id);
        return Reply.success(user);
    }
    @PostMapping("/modify")
    public Reply<User> modify(@RequestBody User user){
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
        userMapper.update(user);
        return Reply.success(user);
    }
    @PostMapping("/add")
    public Reply<User> add(@RequestBody User user){
        user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes()));
        userMapper.insert(user);
        return Reply.success(user);
    }

}
